import Dep from './dep'

class Watcher{

    constructor ( vm, key, cb) {
        this.vm = vm
        this.key = key
        this.cb = cb
        

        //把watcher记录到Dep累的静态熟悉
        Dep.target = this

        this.oldValue = vm[key]
        Dep.target = null
    }
    // key data
    // cb callback
    //vm
    // oldValue

    update(){
        let newValue = this.vm[this.key]
        if (this.oldValue === newValue){
            return
        }
        this.cb(newValue)
    }
}

export default Watcher